package com.wnxy.admin.common.util;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wnxy.admin.entity.ChargingPile;
import com.wnxy.admin.mapper.ChargingPileMapper;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ChargingPileUtil extends ServiceImpl<ChargingPileMapper, ChargingPile> {

    private final ChargingPileMapper chargingPileMapper;

    public ChargingPileUtil(ChargingPileMapper chargingPileMapper) {
        this.chargingPileMapper = chargingPileMapper;
    }

    //根据id修改状态
    public void updateById(Long id){
//        ChargingPile one = lambdaQuery().eq(ChargingPile::getId, id).one();
//        UpdateWrapper<ChargingPile> wrapper = new UpdateWrapper<>();
//        wrapper.lambda()
//                .eq(ChargingPile::getId,id)
//                .set(ChargingPile::getChargingPileState, "预约")
//                .eq(ChargingPile::getChargingPileState, "空闲");
//        return chargingPileMapper.update(one,wrapper);

        List<ChargingPile> piles = chargingPileMapper.selectList(Wrappers.lambdaQuery(ChargingPile.class)
                .eq(ChargingPile::getId,id)
                .eq(ChargingPile::getChargingPileState, "空闲"));
        piles.forEach(pile -> {
            ChargingPile chargingPile = chargingPileMapper.selectById(pile.getId());
            chargingPile.setChargingPileState("预约");
            chargingPileMapper.updateById(chargingPile);
        });
    }
}
